<?php

namespace Modules\Custessa\Entity;

use APP;
use CController as Action;
use Modules\Custessa\Services\WidgetRegistry;

abstract class WidgetAbstract {

    /**
     * Widget default dimensions in blocks.
     */
    const DEFAULT_WIDTH = 2;
    const DEFAULT_HEIGHT = 2;

    /**
     * Default refresh interval value.
     */
    const DEFAULT_REFRESH = SEC_PER_MIN;

    const USE_TIMESELECTOR = false;

    /**
     * Does the widget supports specific context:
     * - WidgetRegistry::CONTEXT_DASHBOARD
     * - WidgetRegistry::CONTEXT_TEMPLATE_DASHBOARD
     *
     * @param string $context  Current context.
     */
    public function supportContext(string $context): bool {
        return ($context === WidgetRegistry::CONTEXT_DASHBOARD);
    }

    /**
     * Set widget settings form initalization context arguments:
     * - (5.0+) array of widget data
     * - (5.2+) string template id for templated dashboards
     */
    public function setFormContextArgumets(array $args) {
        $this->form_context = $args;

        return $this;
    }

    /**
     * Register widget class as accessible widget.
     */
    public static function register($widgetid) {
        $widget = new static;
        APP::Component()->widgets->register($widgetid, $widget);

        return $widget;
    }

    /**
     * Get widget render action handler.
     */
    abstract public function getAction(): Action;

    /**
     * Get widget settings form.
     */
    abstract public function getForm();

    /**
     * Get widget translated label, used in widgets drop down list.
     */
    abstract public function getLabel(): string;
}